package com.chiry.springTask.CategorysUsage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("test")
public class TestController {
    @Autowired
    Map<String,BaseHandler> mapper;


    @RequestMapping("type/{id}")
    public String testMeethod(@PathVariable("id") String data){
        if (StringUtils.isEmpty(data)) {
            return "data is empty";
        }
        BaseHandler handler = mapper.get(data);
        if (handler instanceof BaseHandler) {
            System.out.println("object: "+handler+"type BaseHandler：yes");
        }
        if (StringUtils.isEmpty(handler)) {
            System.out.println("工具类判断对象是为空...");
            return "handler type 不存在、";
        }
        handler.handler(data);
        System.out.println("success .."+handler.getClass().getName());
        return handler.getClass().getName();
    }
}
